<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:p="http://primefaces.org/ui"
                template="/templates/masterLayout.xhtml">

    <ui:define name="pageTitle">#{out.worker_title}</ui:define>
    <ui:define name="header"> -> #{out.worker_title}</ui:define>

    <ui:define name="head-extra">
        <!-- custom css -->
    </ui:define>

    <ui:define name="content">
        <h:form id="orderForm">
            <!--<p:growl id="msgs" showDetail="true" />-->
            <p:messages id="messages" showDetail="true" autoUpdate="true"
                        closable="true" />
            <p:dataTable id="orderTable" var="currentRegistry"
                         value="#{workerController.visibleRegistry}" selectionMode="single"
                         selection="#{workerController.selectedRegistry}"
                         rowKey="#{currentRegistry.id}" paginator="true" rows="10"
                         paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                         rowsPerPageTemplate="5,10,15" lazy="true"
                         emptyMessage="#{out.empty_message}">
                <p:ajax event="rowSelect"
                        update=":orderCommandsForm,:recipeForm:recipe" listener="#{workerController.selectRegistry()}"/>
                <p:ajax event="rowUnselect"
                        update=":orderCommandsForm,:recipeForm:recipe" />

                <p:column headerText="#{out.worker_order_name}"
                          sortBy="#{currentRegistry.beer.name}" filterBy="#{currentRegistry.beer.name}">
                    <h:outputText value="#{currentRegistry.beer.name}" />
                </p:column>
                <p:column headerText="#{out.worker_order_quantity}"
                          sortBy="#{currentRegistry.quantity}" filterBy="#{currentRegistry.quantity}">
                    <h:outputText value="#{currentRegistry.quantity}" />
                </p:column>
            </p:dataTable>

            <h:panelGrid columns="4" cellpadding="5" style="float: right">
                <p:outputLabel value="#{out.worker_print}"/>
                <h:commandLink>
                    <p:graphicImage name="/images/xls.png" width="64" />
                    <p:dataExporter type="xls" encoding="utf-8"
                                    target=":recipeForm:recipe"
                                    fileName="recipe" />
                </h:commandLink>
                <h:commandLink>
                    <p:graphicImage name="/images/pdf.png" width="64" />
                    <p:dataExporter type="pdf" encoding="iso-8859-1"
                                    target=":recipeForm:recipe"
                                    fileName="recipe" />
                </h:commandLink>
                <h:commandLink>
                    <p:graphicImage name="/images/csv.png" width="64" />
                    <p:dataExporter type="csv" encoding="utf-8"
                                    target=":recipeForm:recipe" 
                                    fileName="recipe" />
                </h:commandLink>
            </h:panelGrid>
        </h:form>

        <h:form id="recipeForm" rendered="#{false}">
            <p:dataTable id="recipe" var="currentComponent"  
                         value="#{workerController.recipe}"
                         emptyMessage="#{out.empty_message}">
                <p:column headerText="#{workerController.selectedRegistry.beer.name} #{out.worker_recipe_header}">
                    <h:outputText value="#{currentComponent.name}" />
                </p:column>
                <p:column headerText="#{workerController.selectedRegistry.quantity} #{out.worker_recipe_header_pieces}">
                    <h:outputText value="#{currentComponent.quantity}" />
                </p:column>
                <p:column headerText="#{out.worker_recipe_header_comment}">
                    <h:outputText value="#{currentComponent.comment}" />
                </p:column>
            </p:dataTable>
        </h:form>

        <h:form id="orderCommandsForm">
            <h:panelGrid style="margin-top: 10px">
                <p:outputLabel for="dest_warehouse" value="#{out.worker_add_to_warehouse}: "/>
                <p:selectOneMenu id="dest_warehouse" value="#{workerController.destWarehouse}" style="width:500px">
                    <f:selectItems value="#{workerController.warehouses}"/>
                </p:selectOneMenu>

                <p:commandButton ajax="true"
                                 action="#{workerController.addReadyBeerToWarehouse()}" 
                                 title="#{out.worker_add_to_warehouse}"
                                 value="#{out.worker_add_to_warehouse}"
                                 update=":orderForm:orderTable"
                                 disabled="#{workerController.selectedRegistry == null}">
                </p:commandButton>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>